package com.hwy.chart.component

import android.graphics.Canvas
import android.graphics.Color
import android.graphics.Paint
import android.graphics.RectF
import androidx.annotation.ColorInt

/**
 * =======================================
 * 作者: hewenyu
 * 日期: 2022/5/11 0:20
 * 说明: 组件和光标的交点，默认使用空心圆，其它样式可以继承该组件然后自定义
 * =======================================
 */
open class ComponentFocus {

    private val focusPaint by lazy {
        Paint().apply {
            isDither = true
            isAntiAlias = true
            style = Paint.Style.FILL_AND_STROKE
        }
    }

    /**
     * 整体半径
     */
    var radius: Float = 8F

    /**
     * 边框粗细
     */
    var strokeWidth = 2F

    /**
     * 边框颜色
     */
    @ColorInt
    var strokeColor = Color.RED

    /**
     * 圆圈中心颜色
     */
    @ColorInt
    var innerColor = Color.WHITE

    /**
     * 绘制组件和光标的交叉点
     *
     * @param cx 圆圈中心x坐标
     * @param cy 圆圈中心y坐标
     */
    open fun draw(canvas: Canvas, bounds: RectF, cx: Float?, cy: Float?) {
        cx?.run {
            cy?.run {
                // 先绘大圆圈
                focusPaint.color = strokeColor
                canvas.drawCircle(cx, cy, radius, focusPaint)
                // 覆盖中心点
                focusPaint.color = innerColor
                canvas.drawCircle(cx, cy, radius - strokeWidth, focusPaint)
            }
        }
    }

}